var Module = (function(parent) {
	var my = parent.region = parent.region || {};
	my.center = new Ext.TabPanel( {
		id : 'center-region',
		region : 'center',
		autoScroll : true,
		enableTabScroll : true,
		deferredRender : false,
		activeTab : 0,
		items : [{
			id : 'defaultEditorID',
			contentEl : 'center2',
			title : '默认的首页',
			xtype : 'panel',
			labelAlign : "left",
			layout : "table",
			layoutConfig : {
				columns : 2
			},
			tbar : {
				width : 30,
				items : [{
					id : "newtabbtn",
					icon : 'images/refresh.gif',
					text : '新建',
					tooltip : '新建'
				}]
			},
			items : [ {
				xtype : "panel",
				border : false,
				id : 'ext-radiogroup-panel',
				colspan : 2,
				layoutConfig : {
					deferredRender : false
				},
				layout : "column",
				width : 400,
				style : 'fontSize:16;margin:100 0 5 160', // 上右下左

					items : [{
						xtype : 'radiogroup',
						items : [ {
							boxLabel : 'JavaScript',
							name : 'rb-auto',
							inputValue : 1
						}, {
							boxLabel : 'ExtJS',
							name : 'rb-auto',
							inputValue : 2,
							checked : true
						}, {
							boxLabel : 'Jquery',
							name : 'rb-auto',
							inputValue : 3
						}, {
							boxLabel : 'YUI',
							name : 'rb-auto',
							inputValue : 4
						}, {
							boxLabel : 'RegExp',
							name : 'rb-auto',
							inputValue : 5
						}]
					}]
				}, {
					xtype : "panel",
					id : 'ext-search-text-panel',
					layout : "column",
					width : 700,
					border : false,
					colspan : 2,
					items : [ {
						xtype : "textfield",
						id : 'ext-search-text',
						height : 25,
						style : 'margin:0 5 0 150;font-size: 16px',
						width : 400
					}, {
						xtype : "button",
						height : 25,
						style : 'font-size: 16px',
						handler : doSearch,
						text : "搜索一下"
					}]
				}]
		}]
	});
	// 搜索
	function doSearch() {
		// 获得输入框的内容
		var searchText = Ext.getCmp('ext-search-text').getValue();
		if (searchText == '') {
			log('请输入关键字');
			return;
		}
		var d = ['<li><a href=# >aaaaa</a></li>', '<li>aaaaa</li>',
				'<li>aaaaa</li>', '<li>aaaaa</li>', '<li>aaaaa</li>'];

		var ds = new Ext.data.Store( {
			proxy : new Ext.data.ScriptTagProxy( {
				url : 'http://extjs.com/forum/topics-remote.php'
			}),
			reader : new Ext.data.JsonReader( {
				root : 'topics',
				totalProperty : 'totalCount',
				id : 'post_id'
			}, [ {
				name : 'postId',
				mapping : 'post_id'
			}, {
				name : 'title',
				mapping : 'topic_title'
			}, {
				name : 'topicId',
				mapping : 'topic_id'
			}, {
				name : 'author',
				mapping : 'author'
			}, {
				name : 'lastPost',
				mapping : 'post_time',
				type : 'date',
				dateFormat : 'timestamp'
			}, {
				name : 'excerpt',
				mapping : 'post_text'
			}]),

			baseParams : {
				limit : 20,
				forumId : 4
			}
		});
		var store = new Ext.data.Store( {
			url : 'extAjax',
			reader : new Ext.data.JsonReader( {
				root : 'topics',
				totalProperty : 'totalCount',
				id : 'post_id'
			}, [ {
				name : 'postId',
				mapping : 'post_id'
			}, {
				name : 'title',
				mapping : 'topic_title'
			}, {
				name : 'topicId',
				mapping : 'topic_id'
			}, {
				name : 'author',
				mapping : 'author'
			}, {
				name : 'lastPost',
				mapping : 'post_time',
				type : 'date',
				dateFormat : 'timestamp'
			}, {
				name : 'excerpt',
				mapping : 'post_text'
			}]),

			baseParams : {
				limit : 20,
				saerchText : '*' + searchText + '*',
				mothed : "doSearch",
				forumId : 4
			}
		});

		// Custom rendering Template for the View
		var resultTpl = new Ext.XTemplate(
				'<tpl for=".">',
				'<div class="search-item">',
				'<h3><span>{lastPost:date("M j, Y")}<br />by {author}</span>',
				'<a href="http://extjs.com/forum/showthread.php?t={topicId}&p={postId}" target="_blank">{title}</a></h3>',
				'<p>{excerpt}</p>', '</div></tpl>');

		var panel = new Ext.Panel( {
			height : 500,
			autoScroll : true,
			border : false,
			style : 'margin:10 0 0 0',
			items : new Ext.DataView( {
				tpl : resultTpl,
				store : ds,
				itemSelector : 'div.search-item'
			}),

			bbar : new Ext.PagingToolbar( {
				store : ds,
				pageSize : 20,
				displayInfo : true,
				displayMsg : 'Topics {0} - {1} of {2}',
				emptyMsg : "No topics to display"
			})
		});

		ds.load( {
			params : {
				start : 0,
				limit : 20,
				forumId : 4
			}
		});

		Ext.Ajax
				.request( {
					params : {
						saerchText : '*' + searchText + '*',
						mothed : "doSearch"
					},
					url : "index.do",
					success : function(response) {
						log(response.responseText);
						if (response.statusText == 'OK') {
							Ext.getDom('ext-radiogroup-panel').style.marginLeft = "10px";
							Ext.getDom('ext-radiogroup-panel').style.marginTop = "30px"
							Ext.getDom('ext-search-text').style.marginLeft = "10px";

							var _panel = Ext.getCmp('defaultEditorID');
							_panel.add(panel);
							_panel.doLayout();
						}
						// log(response.responseText);

					},
					onFailure : function(response) {
						logforObject(response);
					}
				});
	};
	var GobalExecutor = {};
	GobalExecutor.execute = function(code) {
		if (!!(window.attachEvent && !window.opera)) {
			// ie
			execScript(code);
		} else {
			// not ie
			window.eval(code);
		}
	};
	// 执行代码
	my.execute = function() {
		var tabs = Ext.getCmp("center-region");
		var p = tabs.getActiveTab();
		var _panel = p.items.item("hlt");
		var tab_code = _panel.getCode();
		tab_code = tab_code.replace(/&lt;/g, '<');
		tab_code = tab_code.replace(/&gt;/g, '>');
		// log(tab_code);
		// alert(tab_code);
		// var tab_code="for(var temp in d ) {
		// Ext.log(temp+':'+d[temp])} ;
		GobalExecutor.execute(tab_code);
		// d.show();

	};
	// 插入注释
	my.doAnnotation = function() {
		var tabs = Ext.getCmp("center-region");
		var p = tabs.getActiveTab();
	};
	return parent;
}(Module || {}));